package com.bwie.kanjia.service.impl;

import com.bwie.common.utils.R;
import com.bwie.kanjia.dao.ActDao;
import com.bwie.kanjia.entity.ActEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.Query;

import com.bwie.kanjia.dao.OrderDao;
import com.bwie.kanjia.entity.OrderEntity;
import com.bwie.kanjia.service.OrderService;


@Service("orderService")
public class OrderServiceImpl extends ServiceImpl<OrderDao, OrderEntity> implements OrderService {

    @Autowired
    private ActDao actDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<OrderEntity> page = this.page(
                new Query<OrderEntity>().getPage(params),
                new QueryWrapper<OrderEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public R save1(OrderEntity order) {

        order.setOrderTime(new Date());//参与活动时间
        order.setOrderNum(0);//初始值砍价次数
        order.setOrderPrice(0.00);//砍价价钱
        baseMapper.insert(order);
        return R.ok();
    }

    @Override
    public R list1(Integer actId, Long userId) {

        //根据id获取活动信息
        ActEntity actEntity = actDao.selectById(actId);


        //根据act和userid查找对应活动
        List<OrderEntity> list=baseMapper.selectByUIdAndAId(actEntity,userId);

        return R.ok().put("list",list);

    }

}